package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {

	reader := bufio.NewReader(os.Stdin)
	fmt.Println("input an integer number and program will out put square value of this number!")
	fmt.Println("enter \"exit\" to exit program!")
	fmt.Println("---------------------")

	for {
		fmt.Print("-> ")
		text, _ := reader.ReadString('\n')
		// convert CRLF to LF
		text = strings.Replace(text, "\n", "", -1)
		text = strings.Replace(text, "\r", "", -1)

		if strings.Compare("exit", text) == 0 {
			fmt.Println("Goodbye~~~")
			break
		}
		i, err := strconv.Atoi(text)
		if err != nil {
			fmt.Print("input error! you should input an integer number!\n")
		} else {
			printSquareVal(i)
		}
	}
}

func printSquareVal(a int) int {
	c := a * a
	fmt.Printf("%d square val : %d \n", a, c)
	return c
}
